package cn.tedu.jxc.web;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.List;

@Data
@Slf4j
public class JsonPage<T> implements Serializable {
    //自定义声明属性

    private List<T> list;
    private Long totalPage;
    private Integer totalCount;
    private Integer page;
    private Integer pageSize;

    //pageInfo转换为JsonPage的方法
    public static<T> JsonPage<T> restPage(PageInfo<T> pageInfo){
        JsonPage<T> jsonPage = new JsonPage<>();
        jsonPage.setList(pageInfo.getList());
        jsonPage.setTotalPage(pageInfo.getTotal());
        jsonPage.setTotalCount(pageInfo.getPages());
        jsonPage.setPage(pageInfo.getPageNum());
        jsonPage.setPageSize(pageInfo.getPageSize());
        return jsonPage;
    }
}
